import 'package:flutter/material.dart';
import 'package:navigator_demo/navigator1pointzero/bottom_bar_menu_page.dart';
import 'package:navigator_demo/navigator_ver01.dart';
import 'package:navigator_demo/navigator_warpper/page_navigator.dart';

class TabB extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    print('====== TabA  build ====== 2');
    return Scaffold(
      appBar: AppBar(
        title: Text('tab_b.dart'),
      ),
      body: ListView(children: [
        ListTile(
          title: Text('goto tab1 /A/B/C'),
          onTap: () {
            try {
              context.findAncestorWidgetOfExactType<BottmBarMenuPage>()
                ..tabIndexNotifier.value = 1
                ..navigate = (_) {
                  PageNavigator.of(context)
                      .subpageNavigator
                      ?.pushNamed('C', arguments: [
                    'A',
                    'B',
                  ]);
                };
            } on Object catch (e, s) {
              print('current is not under the `BottmBarMenuPage` tree $e,$s');
            }
          },
          trailing: Icon(Icons.arrow_right),
        ),
        ListTile(
          title: Text('push /A/B/C'),
          onTap: () {
            Navigator.of(context).pushNamed('C', arguments: [
              'A',
              'B',
            ]);
          },
          trailing: Icon(Icons.arrow_right),
        ),
        ListTile(
            title: Text('change bottom tab'),
            onTap: () {
              context
                  .findAncestorWidgetOfExactType<HomePage>()
                  .bottomMenuPageNotifier
                  .value = (context
                          .findAncestorWidgetOfExactType<HomePage>()
                          .bottomMenuPageNotifier
                          .value +
                      1) %
                  2;
            }),
      ]),
    );
  }
}
